/*
提交链接:https://leetcode.cn/problems/minimum-insertion-steps-to-make-a-string-palindrome/description/
1312. [让字符串成为回文串的最少插入次数 1787]
赖德檀 2024/10/23
*/
  
class Solution {
public:
    int minInsertions(string s) {
        int n=s.size();
        string t=s;
        vector<vector<int>>dp(n+1,vector<int>(n+1,0));
        reverse(t.begin(),t.end());
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(s[i-1]==t[j-1])
                dp[i][j]+=dp[i-1][j-1]+1;
                else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        return n-dp[n][n];
    }
};
